forked from gen2brain/raylib-go
/
rcore.go
925 lines (793 loc) · 22.7 KB
/
rcore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
package rl
/*
#include "raylib.h"
#include <stdlib.h>
*/
import "C"
import (
"image/color"
"unsafe"
)
// cptr returns C pointer
func (v *Vector2[T]) cptr() *C.Vector2 {
return (*C.Vector2)(unsafe.Pointer(v))
}
// cptr returns C pointer
func (v *Vector3) cptr() *C.Vector3 {
return (*C.Vector3)(unsafe.Pointer(v))
}
// cptr returns C pointer
func (v *Vector4) cptr() *C.Vector4 {
return (*C.Vector4)(unsafe.Pointer(v))
}
// cptr returns C pointer
func (m *Matrix) cptr() *C.Matrix {
return (*C.Matrix)(unsafe.Pointer(m))
}
// colorCptr returns color C pointer
func colorCptr(col color.RGBA) *C.Color {
return (*C.Color)(unsafe.Pointer(&col))
}
// cptr returns C pointer
func (r *Rectangle) cptr() *C.Rectangle {
return (*C.Rectangle)(unsafe.Pointer(r))
}
// cptr returns C pointer
func (c *Camera) cptr() *C.Camera {
return (*C.Camera)(unsafe.Pointer(c))
}
// cptr returns C pointer
func (c *Camera2D[T]) cptr() *C.Camera2D {
return (*C.Camera2D)(unsafe.Pointer(c))
}
// cptr returns C pointer
func (b *BoundingBox) cptr() *C.BoundingBox {
return (*C.BoundingBox)(unsafe.Pointer(b))
}
// WindowShouldClose - Check if KEY_ESCAPE pressed or Close icon pressed
func WindowShouldClose() bool {
ret := C.WindowShouldClose()
v := bool(ret)
return v
}
// CloseWindow - Close Window and Terminate Context
func CloseWindow() {
C.CloseWindow()
}
// IsWindowReady - Check if window has been initialized successfully
func IsWindowReady() bool {
ret := C.IsWindowReady()
v := bool(ret)
return v
}
// IsWindowFullscreen - Check if window is currently fullscreen
func IsWindowFullscreen() bool {
ret := C.IsWindowFullscreen()
v := bool(ret)
return v
}
// IsWindowHidden - Check if window is currently hidden
func IsWindowHidden() bool {
ret := C.IsWindowHidden()
v := bool(ret)
return v
}
// IsWindowMinimized - Check if window is currently minimized
func IsWindowMinimized() bool {
ret := C.IsWindowMinimized()
v := bool(ret)
return v
}
// IsWindowMaximized - Check if window is currently maximized
func IsWindowMaximized() bool {
ret := C.IsWindowMaximized()
v := bool(ret)
return v
}
// IsWindowFocused - Check if window is currently focused
func IsWindowFocused() bool {
ret := C.IsWindowFocused()
v := bool(ret)
return v
}
// IsWindowResized - Check if window has been resized
func IsWindowResized() bool {
ret := C.IsWindowResized()
v := bool(ret)
return v
}
// IsWindowState - Check if one specific window flag is enabled
func IsWindowState(flag uint32) bool {
cflag := (C.uint)(flag)
ret := C.IsWindowState(cflag)
v := bool(ret)
return v
}
// SetWindowState - Set window configuration state using flags
func SetWindowState(flags uint32) {
cflags := (C.uint)(flags)
C.SetWindowState(cflags)
}
// ClearWindowState - Clear window configuration state flags
func ClearWindowState(flags uint32) {
cflags := (C.uint)(flags)
C.ClearWindowState(cflags)
}
// ToggleFullscreen - Fullscreen toggle (only PLATFORM_DESKTOP)
func ToggleFullscreen() {
C.ToggleFullscreen()
}
// MaximizeWindow - Set window state: maximized, if resizable
func MaximizeWindow() {
C.MaximizeWindow()
}
// MinimizeWindow - Set window state: minimized, if resizable
func MinimizeWindow() {
C.MinimizeWindow()
}
// RestoreWindow - Set window state: not minimized/maximized
func RestoreWindow() {
C.RestoreWindow()
}
// SetWindowIcon - Set icon for window (only PLATFORM_DESKTOP)
func SetWindowIcon(image Image) {
cimage := image.cptr()
C.SetWindowIcon(*cimage)
}
// SetWindowTitle - Set title for window (only PLATFORM_DESKTOP)
func SetWindowTitle(title string) {
ctitle := C.CString(title)
defer C.free(unsafe.Pointer(ctitle))
C.SetWindowTitle(ctitle)
}
// SetWindowPosition - Set window position on screen (only PLATFORM_DESKTOP)
func SetWindowPosition(x, y int) {
cx := (C.int)(x)
cy := (C.int)(y)
C.SetWindowPosition(cx, cy)
}
// SetWindowMonitor - Set monitor for the current window (fullscreen mode)
func SetWindowMonitor(monitor int) {
cmonitor := (C.int)(monitor)
C.SetWindowMonitor(cmonitor)
}
// SetWindowMinSize - Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
func SetWindowMinSize(w, h int) {
cw := (C.int)(w)
ch := (C.int)(h)
C.SetWindowMinSize(cw, ch)
}
// SetWindowSize - Set window dimensions
func SetWindowSize(w, h int) {
cw := (C.int)(w)
ch := (C.int)(h)
C.SetWindowSize(cw, ch)
}
// SetWindowOpacity - Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
func SetWindowOpacity(opacity float32) {
copacity := (C.float)(opacity)
C.SetWindowOpacity(copacity)
}
// GetWindowHandle - Get native window handle
func GetWindowHandle() unsafe.Pointer {
v := unsafe.Pointer((C.GetWindowHandle()))
return v
}
// GetScreenWidth - Get current screen width
func GetScreenWidth() int {
ret := C.GetScreenWidth()
v := (int)(ret)
return v
}
// GetScreenHeight - Get current screen height
func GetScreenHeight() int {
ret := C.GetScreenHeight()
v := (int)(ret)
return v
}
// GetRenderWidth - Get current render width (it considers HiDPI)
func GetRenderWidth() int {
ret := C.GetRenderWidth()
v := (int)(ret)
return v
}
// GetRenderHeight - Get current render height (it considers HiDPI)
func GetRenderHeight() int {
ret := C.GetRenderHeight()
v := (int)(ret)
return v
}
// GetMonitorCount - Get number of connected monitors
func GetMonitorCount() int {
ret := C.GetMonitorCount()
v := (int)(ret)
return v
}
// GetCurrentMonitor - Get current connected monitor
func GetCurrentMonitor() int {
ret := C.GetCurrentMonitor()
v := (int)(ret)
return v
}
// GetMonitorPosition - Get specified monitor position
func GetMonitorPosition[T Number](monitor int) Vector2[T] {
cmonitor := (C.int)(monitor)
ret := C.GetMonitorPosition(cmonitor)
v := newVector2FromPointer[T](unsafe.Pointer(&ret))
return v
}
// GetMonitorWidth - Get primary monitor width
func GetMonitorWidth(monitor int) int {
cmonitor := (C.int)(monitor)
ret := C.GetMonitorWidth(cmonitor)
v := (int)(ret)
return v
}
// GetMonitorHeight - Get primary monitor height
func GetMonitorHeight(monitor int) int {
cmonitor := (C.int)(monitor)
ret := C.GetMonitorHeight(cmonitor)
v := (int)(ret)
return v
}
// GetMonitorPhysicalWidth - Get primary monitor physical width in millimetres
func GetMonitorPhysicalWidth(monitor int) int {
cmonitor := (C.int)(monitor)
ret := C.GetMonitorPhysicalWidth(cmonitor)
v := (int)(ret)
return v
}
// GetMonitorPhysicalHeight - Get primary monitor physical height in millimetres
func GetMonitorPhysicalHeight(monitor int) int {
cmonitor := (C.int)(monitor)
ret := C.GetMonitorPhysicalHeight(cmonitor)
v := (int)(ret)
return v
}
// GetMonitorRefreshRate - Get specified monitor refresh rate
func GetMonitorRefreshRate(monitor int) int {
cmonitor := (C.int)(monitor)
ret := C.GetMonitorRefreshRate(cmonitor)
v := (int)(ret)
return v
}
// GetWindowPosition - Get window position XY on monitor
func GetWindowPosition[T Number]() Vector2[T] {
ret := C.GetWindowPosition()
v := newVector2FromPointer[T](unsafe.Pointer(&ret))
return v
}
// GetWindowScaleDPI - Get window scale DPI factor
func GetWindowScaleDPI[T Number]() Vector2[T] {
ret := C.GetWindowScaleDPI()
v := newVector2FromPointer[T](unsafe.Pointer(&ret))
return v
}
// GetMonitorName - Get the human-readable, UTF-8 encoded name of the primary monitor
func GetMonitorName(monitor int) string {
cmonitor := (C.int)(monitor)
ret := C.GetMonitorName(cmonitor)
v := C.GoString(ret)
return v
}
// SetClipboardText - Set clipboard text content
func SetClipboardText(data string) {
cdata := C.CString(data)
defer C.free(unsafe.Pointer(cdata))
C.SetClipboardText(cdata)
}
// GetClipboardText - Get clipboard text content
func GetClipboardText() string {
ret := C.GetClipboardText()
v := C.GoString(ret)
return v
}
// EnableEventWaiting - Enable waiting for events on EndDrawing(), no automatic event polling
func EnableEventWaiting() {
C.EnableEventWaiting()
}
// DisableEventWaiting - Disable waiting for events on EndDrawing(), automatic events polling
func DisableEventWaiting() {
C.DisableEventWaiting()
}
// ClearBackground - Sets Background Color
func ClearBackground(col color.RGBA) {
ccolor := colorCptr(col)
C.ClearBackground(*ccolor)
}
// BeginDrawing - Setup drawing canvas to start drawing
func BeginDrawing() {
C.BeginDrawing()
}
// EndDrawing - End canvas drawing and Swap Buffers (Double Buffering)
func EndDrawing() {
C.EndDrawing()
}
// BeginMode2D - Initialize 2D mode with custom camera
func BeginMode2D[T Number](camera Camera2D[T]) {
ccamera := camera.cptr()
C.BeginMode2D(*ccamera)
}
// EndMode2D - Ends 2D mode custom camera usage
func EndMode2D() {
C.EndMode2D()
}
// BeginMode3D - Initializes 3D mode for drawing (Camera setup)
func BeginMode3D(camera Camera) {
ccamera := camera.cptr()
C.BeginMode3D(*ccamera)
}
// EndMode3D - Ends 3D mode and returns to default 2D orthographic mode
func EndMode3D() {
C.EndMode3D()
}
// BeginTextureMode - Initializes render texture for drawing
func BeginTextureMode(target RenderTexture2D) {
ctarget := target.cptr()
C.BeginTextureMode(*ctarget)
}
// EndTextureMode - Ends drawing to render texture
func EndTextureMode() {
C.EndTextureMode()
}
// BeginScissorMode - Begins scissor mode (define screen area for following drawing)
func BeginScissorMode(x, y, width, height int32) {
cx := (C.int)(x)
cy := (C.int)(y)
cwidth := (C.int)(width)
cheight := (C.int)(height)
C.BeginScissorMode(cx, cy, cwidth, cheight)
}
// EndScissorMode - Ends scissor mode
func EndScissorMode() {
C.EndScissorMode()
}
// GetMouseRay - Returns a ray trace from mouse position
func GetMouseRay[T Number](mousePosition Vector2[T], camera Camera) Ray {
cmousePosition := mousePosition.cptr()
ccamera := camera.cptr()
ret := C.GetMouseRay(*cmousePosition, *ccamera)
v := newRayFromPointer(unsafe.Pointer(&ret))
return v
}
// GetCameraMatrix - Returns camera transform matrix (view matrix)
func GetCameraMatrix(camera Camera) Matrix {
ccamera := camera.cptr()
ret := C.GetCameraMatrix(*ccamera)
v := newMatrixFromPointer(unsafe.Pointer(&ret))
return v
}
// GetCameraMatrix2D - Returns camera 2d transform matrix
func GetCameraMatrix2D[T Number](camera Camera2D[T]) Matrix {
ccamera := camera.cptr()
ret := C.GetCameraMatrix2D(*ccamera)
v := newMatrixFromPointer(unsafe.Pointer(&ret))
return v
}
// GetWorldToScreen - Returns the screen space position from a 3d world space position
func GetWorldToScreen[T Number](position Vector3, camera Camera) Vector2[T] {
cposition := position.cptr()
ccamera := camera.cptr()
ret := C.GetWorldToScreen(*cposition, *ccamera)
v := newVector2FromPointer[T](unsafe.Pointer(&ret))
return v
}
// GetScreenToWorld2D - Returns the world space position for a 2d camera screen space position
func GetScreenToWorld2D[T Number](position Vector2[T], camera Camera2D[T]) Vector2[T] {
cposition := position.cptr()
ccamera := camera.cptr()
ret := C.GetScreenToWorld2D(*cposition, *ccamera)
v := newVector2FromPointer[T](unsafe.Pointer(&ret))
return v
}
// GetWorldToScreenEx - Get size position for a 3d world space position
func GetWorldToScreenEx[T Number](position Vector3, camera Camera, width int32, height int32) Vector2[T] {
cposition := position.cptr()
ccamera := camera.cptr()
cwidth := (C.int)(width)
cheight := (C.int)(height)
ret := C.GetWorldToScreenEx(*cposition, *ccamera, cwidth, cheight)
v := newVector2FromPointer[T](unsafe.Pointer(&ret))
return v
}
// GetWorldToScreen2D - Returns the screen space position for a 2d camera world space position
func GetWorldToScreen2D[T Number](position Vector2[T], camera Camera2D[T]) Vector2[T] {
cposition := position.cptr()
ccamera := camera.cptr()
ret := C.GetWorldToScreen2D(*cposition, *ccamera)
v := newVector2FromPointer[T](unsafe.Pointer(&ret))
return v
}
// SetTargetFPS - Set target FPS (maximum)
func SetTargetFPS(fps int32) {
cfps := (C.int)(fps)
C.SetTargetFPS(cfps)
}
// GetFPS - Returns current FPS
func GetFPS() float32 {
ret := C.GetFPS()
v := (float32)(ret)
return v
}
// GetFrameTime - Returns time in seconds for one frame
func GetFrameTime() float32 {
ret := C.GetFrameTime()
v := (float32)(ret)
return v
}
// GetTime - Return time in seconds
func GetTime() float64 {
ret := C.GetTime()
v := (float64)(ret)
return v
}
// Fade - Returns color with alpha applied, alpha goes from 0.0f to 1.0f
func Fade(col color.RGBA, alpha float32) color.RGBA {
ccolor := colorCptr(col)
calpha := (C.float)(alpha)
ret := C.Fade(*ccolor, calpha)
v := newColorFromPointer(unsafe.Pointer(&ret))
return v
}
// ColorToInt - Returns hexadecimal value for a Color
func ColorToInt(col color.RGBA) int32 {
ccolor := colorCptr(col)
ret := C.ColorToInt(*ccolor)
v := (int32)(ret)
return v
}
// ColorNormalize - Returns color normalized as float [0..1]
func ColorNormalize(col color.RGBA) Vector4 {
result := Vector4{}
r, g, b, a := col.RGBA()
result.X = float32(r) / 255
result.Y = float32(g) / 255
result.Z = float32(b) / 255
result.W = float32(a) / 255
return result
}
// ColorFromNormalized - Returns Color from normalized values [0..1]
func ColorFromNormalized(normalized Vector4) color.RGBA {
cnormalized := normalized.cptr()
ret := C.ColorFromNormalized(*cnormalized)
v := newColorFromPointer(unsafe.Pointer(&ret))
return v
}
// ColorToHSV - Returns HSV values for a Color, hue [0..360], saturation/value [0..1]
func ColorToHSV(col color.RGBA) Vector3 {
ccolor := colorCptr(col)
ret := C.ColorToHSV(*ccolor)
v := newVector3FromPointer(unsafe.Pointer(&ret))
return v
}
// ColorFromHSV - Returns a Color from HSV values, hue [0..360], saturation/value [0..1]
func ColorFromHSV(hue, saturation, value float32) color.RGBA {
chue := (C.float)(hue)
csaturation := (C.float)(saturation)
cvalue := (C.float)(value)
ret := C.ColorFromHSV(chue, csaturation, cvalue)
v := newColorFromPointer(unsafe.Pointer(&ret))
return v
}
// ColorAlpha - Returns color with alpha applied, alpha goes from 0.0f to 1.0f
func ColorAlpha(col color.RGBA, alpha float32) color.RGBA {
return Fade(col, alpha)
}
// ColorAlphaBlend - Returns src alpha-blended into dst color with tint
func ColorAlphaBlend(src, dst, tint color.RGBA) color.RGBA {
csrc := colorCptr(src)
cdst := colorCptr(dst)
ctint := colorCptr(tint)
ret := C.ColorAlphaBlend(*csrc, *cdst, *ctint)
v := newColorFromPointer(unsafe.Pointer(&ret))
return v
}
// GetColor - Returns a Color struct from hexadecimal value
func GetColor(hexValue uint) color.RGBA {
chexValue := (C.uint)(hexValue)
ret := C.GetColor(chexValue)
v := newColorFromPointer(unsafe.Pointer(&ret))
return v
}
// GetPixelDataSize - Get pixel data size in bytes for certain format
func GetPixelDataSize(width, height, format int32) int32 {
cwidth := (C.int)(width)
cheight := (C.int)(height)
cformat := (C.int)(format)
ret := C.GetPixelDataSize(cwidth, cheight, cformat)
v := (int32)(ret)
return v
}
// Vector3ToFloat - Converts Vector3 to float32 slice
func Vector3ToFloat(vec Vector3) []float32 {
data := make([]float32, 0)
data[0] = vec.X
data[1] = vec.Y
data[2] = vec.Z
return data
}
// MatrixToFloat - Converts Matrix to float32 slice
func MatrixToFloat(mat Matrix) []float32 {
data := make([]float32, 0)
data[0] = mat.M0
data[1] = mat.M4
data[2] = mat.M8
data[3] = mat.M12
data[4] = mat.M1
data[5] = mat.M5
data[6] = mat.M9
data[7] = mat.M13
data[8] = mat.M2
data[9] = mat.M6
data[10] = mat.M10
data[11] = mat.M14
data[12] = mat.M3
data[13] = mat.M7
data[14] = mat.M11
data[15] = mat.M15
return data
}
// GetRandomValue - Returns a random value between min and max (both included)
func GetRandomValue(min, max int32) int32 {
cmin := (C.int)(min)
cmax := (C.int)(max)
ret := C.GetRandomValue(cmin, cmax)
v := (int32)(ret)
return v
}
// OpenURL - Open URL with default system browser (if available)
func OpenURL(url string) {
curl := C.CString(url)
defer C.free(unsafe.Pointer(curl))
C.OpenURL(curl)
}
// SetConfigFlags - Setup some window configuration flags
func SetConfigFlags(flags uint32) {
cflags := (C.uint)(flags)
C.SetConfigFlags(cflags)
}
// TakeScreenshot - Takes a screenshot of current screen (saved a .png)
func TakeScreenshot(name string) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
C.TakeScreenshot(cname)
}
// IsKeyPressed - Detect if a key has been pressed once
func IsKeyPressed(key int32) bool {
ckey := (C.int)(key)
ret := C.IsKeyPressed(ckey)
v := bool(ret)
return v
}
// IsKeyDown - Detect if a key is being pressed
func IsKeyDown(key int32) bool {
ckey := (C.int)(key)
ret := C.IsKeyDown(ckey)
v := bool(ret)
return v
}
// IsKeyReleased - Detect if a key has been released once
func IsKeyReleased(key int32) bool {
ckey := (C.int)(key)
ret := C.IsKeyReleased(ckey)
v := bool(ret)
return v
}
// IsKeyUp - Detect if a key is NOT being pressed
func IsKeyUp(key int32) bool {
ckey := (C.int)(key)
ret := C.IsKeyUp(ckey)
v := bool(ret)
return v
}
// GetKeyPressed - Get latest key pressed
func GetKeyPressed() int32 {
ret := C.GetKeyPressed()
v := (int32)(ret)
return v
}
// GetCharPressed - Get the last char pressed
func GetCharPressed() int32 {
ret := C.GetCharPressed()
v := (int32)(ret)
return v
}
// SetExitKey - Set a custom key to exit program (default is ESC)
func SetExitKey(key int32) {
ckey := (C.int)(key)
C.SetExitKey(ckey)
}
// IsGamepadAvailable - Detect if a gamepad is available
func IsGamepadAvailable(gamepad int32) bool {
cgamepad := (C.int)(gamepad)
ret := C.IsGamepadAvailable(cgamepad)
v := bool(ret)
return v
}
// GetGamepadName - Return gamepad internal name id
func GetGamepadName(gamepad int32) string {
cgamepad := (C.int)(gamepad)
ret := C.GetGamepadName(cgamepad)
v := C.GoString(ret)
return v
}
// IsGamepadButtonPressed - Detect if a gamepad button has been pressed once
func IsGamepadButtonPressed(gamepad, button int32) bool {
cgamepad := (C.int)(gamepad)
cbutton := (C.int)(button)
ret := C.IsGamepadButtonPressed(cgamepad, cbutton)
v := bool(ret)
return v
}
// IsGamepadButtonDown - Detect if a gamepad button is being pressed
func IsGamepadButtonDown(gamepad, button int32) bool {
cgamepad := (C.int)(gamepad)
cbutton := (C.int)(button)
ret := C.IsGamepadButtonDown(cgamepad, cbutton)
v := bool(ret)
return v
}
// IsGamepadButtonReleased - Detect if a gamepad button has been released once
func IsGamepadButtonReleased(gamepad, button int32) bool {
cgamepad := (C.int)(gamepad)
cbutton := (C.int)(button)
ret := C.IsGamepadButtonReleased(cgamepad, cbutton)
v := bool(ret)
return v
}
// IsGamepadButtonUp - Detect if a gamepad button is NOT being pressed
func IsGamepadButtonUp(gamepad, button int32) bool {
cgamepad := (C.int)(gamepad)
cbutton := (C.int)(button)
ret := C.IsGamepadButtonUp(cgamepad, cbutton)
v := bool(ret)
return v
}
// GetGamepadButtonPressed - Get the last gamepad button pressed
func GetGamepadButtonPressed() int32 {
ret := C.GetGamepadButtonPressed()
v := (int32)(ret)
return v
}
// GetGamepadAxisCount - Return gamepad axis count for a gamepad
func GetGamepadAxisCount(gamepad int32) int32 {
cgamepad := (C.int)(gamepad)
ret := C.GetGamepadAxisCount(cgamepad)
v := (int32)(ret)
return v
}
// GetGamepadAxisMovement - Return axis movement value for a gamepad axis
func GetGamepadAxisMovement(gamepad, axis int32) float32 {
cgamepad := (C.int)(gamepad)
caxis := (C.int)(axis)
ret := C.GetGamepadAxisMovement(cgamepad, caxis)
v := (float32)(ret)
return v
}
// SetGamepadMappings - Set internal gamepad mappings (SDL_GameControllerDB)
func SetGamepadMappings(mappings string) int32 {
cmappings := C.CString(mappings)
defer C.free(unsafe.Pointer(cmappings))
ret := C.SetGamepadMappings(cmappings)
v := (int32)(ret)
return v
}
// IsMouseButtonPressed - Detect if a mouse button has been pressed once
func IsMouseButtonPressed(button int32) bool {
cbutton := (C.int)(button)
ret := C.IsMouseButtonPressed(cbutton)
v := bool(ret)
return v
}
// IsMouseButtonDown - Detect if a mouse button is being pressed
func IsMouseButtonDown(button int32) bool {
cbutton := (C.int)(button)
ret := C.IsMouseButtonDown(cbutton)
v := bool(ret)
return v
}
// IsMouseButtonReleased - Detect if a mouse button has been released once
func IsMouseButtonReleased(button int32) bool {
cbutton := (C.int)(button)
ret := C.IsMouseButtonReleased(cbutton)
v := bool(ret)
return v
}
// IsMouseButtonUp - Detect if a mouse button is NOT being pressed
func IsMouseButtonUp(button int32) bool {
cbutton := (C.int)(button)
ret := C.IsMouseButtonUp(cbutton)
v := bool(ret)
return v
}
// GetMouseX - Returns mouse position X
func GetMouseX() int32 {
ret := C.GetMouseX()
v := (int32)(ret)
return v
}
// GetMouseY - Returns mouse position Y
func GetMouseY() int32 {
ret := C.GetMouseY()
v := (int32)(ret)
return v
}
// GetMousePosition - Returns mouse position XY
func GetMousePosition[T Number]() Vector2[T] {
ret := C.GetMousePosition()
v := newVector2FromPointer[T](unsafe.Pointer(&ret))
return v
}
// GetMouseDelta - Get mouse delta between frames
func GetMouseDelta[T Number]() Vector2[T] {
ret := C.GetMouseDelta()
v := newVector2FromPointer[T](unsafe.Pointer(&ret))
return v
}
// SetMousePosition - Set mouse position XY
func SetMousePosition(x, y int) {
cx := (C.int)(x)
cy := (C.int)(y)
C.SetMousePosition(cx, cy)
}
// SetMouseOffset - Set mouse offset
func SetMouseOffset(offsetX, offsetY int) {
ox := (C.int)(offsetX)
oy := (C.int)(offsetY)
C.SetMouseOffset(ox, oy)
}
// SetMouseScale - Set mouse scaling
func SetMouseScale(scaleX, scaleY float32) {
cscaleX := (C.float)(scaleX)
cscaleY := (C.float)(scaleY)
C.SetMouseScale(cscaleX, cscaleY)
}
// GetMouseWheelMove - Get mouse wheel movement for X or Y, whichever is larger
func GetMouseWheelMove() float32 {
ret := C.GetMouseWheelMove()
v := (float32)(ret)
return v
}
// GetMouseWheelMoveV - Get mouse wheel movement for both X and Y
func GetMouseWheelMoveV[T Number]() Vector2[T] {
ret := C.GetMouseWheelMoveV()
v := newVector2FromPointer[T](unsafe.Pointer(&ret))
return v
}
// SetMouseCursor - Set mouse cursor
func SetMouseCursor(cursor int32) {
ccursor := (C.int)(cursor)
C.SetMouseCursor(ccursor)
}
// GetTouchX - Returns touch position X for touch point 0 (relative to screen size)
func GetTouchX() int32 {
ret := C.GetTouchX()
v := (int32)(ret)
return v
}
// GetTouchY - Returns touch position Y for touch point 0 (relative to screen size)
func GetTouchY() int32 {
ret := C.GetTouchY()
v := (int32)(ret)
return v
}
// GetTouchPosition - Returns touch position XY for a touch point index (relative to screen size)
func GetTouchPosition[T Number](index int32) Vector2[T] {
cindex := (C.int)(index)
ret := C.GetTouchPosition(cindex)
v := newVector2FromPointer[T](unsafe.Pointer(&ret))
return v
}
// GetTouchPointId - Get touch point identifier for given index
func GetTouchPointId(index int32) int32 {
cindex := (C.int)(index)
ret := C.GetTouchPointId(cindex)
v := (int32)(ret)
return v
}
// GetTouchPointCount - Get number of touch points
func GetTouchPointCount() int32 {
ret := C.GetTouchPointCount()
v := (int32)(ret)
return v
}