mode.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // acodec
  2. package al
  3. /*
  4. #cgo pkg-config: allegro-5
  5. #cgo CFLAGS: -I/usr/local/include
  6. #cgo linux LDFLAGS: -lc_nonshared
  7. #include <stdlib.h>
  8. #include <allegro5/allegro.h>
  9. #include <allegro5/fullscreen_mode.h>
  10. #include "helpers.h"
  11. */
  12. import "C"
  13. import "fmt"
  14. type DisplayMode C.ALLEGRO_DISPLAY_MODE
  15. func (dm * DisplayMode) toC() * C.ALLEGRO_DISPLAY_MODE {
  16. return (*C.ALLEGRO_DISPLAY_MODE)(dm)
  17. }
  18. func (dm * DisplayMode) Width() int {
  19. return int(dm.width)
  20. }
  21. func (dm * DisplayMode) Height() int {
  22. return int(dm.height)
  23. }
  24. func (dm * DisplayMode) Format() int {
  25. return int(dm.format)
  26. }
  27. func (dm * DisplayMode) RefreshRate() int {
  28. return int(dm.refresh_rate)
  29. }
  30. func (dm * DisplayMode) String() string {
  31. return fmt.Sprintf("(%d %d) %d %d hz", dm.Width(), dm.Height(), dm.Format(), dm.RefreshRate() )
  32. }
  33. func NumDisplayModes() int {
  34. return int(C.al_get_num_display_modes())
  35. }
  36. func FindDisplayMode(index int) (disp * DisplayMode) {
  37. disp = &DisplayMode{}
  38. if nil == C.al_get_display_mode(C.int(index), disp.toC()) {
  39. return nil
  40. }
  41. return disp
  42. }
  43. func DisplayModes() (modes [] *DisplayMode) {
  44. count := NumDisplayModes()
  45. modes = make([]*DisplayMode, count)
  46. for i:=0 ; i < count ; i ++ {
  47. modes[i] = FindDisplayMode(i)
  48. }
  49. return modes
  50. }
  51. /* vim: set ts=8 sts=3 sw=3 et: */