mode.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "callbacks.h"
  12. */
  13. import "C"
  14. import "fmt"
  15. type DisplayMode C.ALLEGRO_DISPLAY_MODE
  16. func (dm * DisplayMode) toC() * C.ALLEGRO_DISPLAY_MODE {
  17. return (*C.ALLEGRO_DISPLAY_MODE)(dm)
  18. }
  19. func (dm * DisplayMode) Width() int {
  20. return int(dm.width)
  21. }
  22. func (dm * DisplayMode) Height() int {
  23. return int(dm.height)
  24. }
  25. func (dm * DisplayMode) Format() int {
  26. return int(dm.format)
  27. }
  28. func (dm * DisplayMode) RefreshRate() int {
  29. return int(dm.refresh_rate)
  30. }
  31. func (dm * DisplayMode) String() string {
  32. return fmt.Sprintf("(%d %d) %d %d hz", dm.Width(), dm.Height(), dm.Format(), dm.RefreshRate() )
  33. }
  34. func NumDisplayModes() int {
  35. return int(C.al_get_num_display_modes())
  36. }
  37. func GetDisplayMode(index int) (disp * DisplayMode) {
  38. disp = &DisplayMode{}
  39. if nil == C.al_get_display_mode(C.int(index), disp.toC()) {
  40. return nil
  41. }
  42. return disp
  43. }
  44. func DisplayModes() (modes [] *DisplayMode) {
  45. count := NumDisplayModes()
  46. modes = make([]*DisplayMode, count)
  47. for i:=0 ; i < count ; i ++ {
  48. modes[i] = GetDisplayMode(i)
  49. }
  50. return modes
  51. }
  52. /* vim: set ts=8 sts=3 sw=3 et: */