Browse Source

Test monitor info and wrap keyboard state.

Beoran 6 years ago
parent
commit
bc14108ca9
3 changed files with 39 additions and 1 deletions
  1. 6 1
      al/al_test.go
  2. 15 0
      al/display.go
  3. 18 0
      al/keyboard.go

+ 6 - 1
al/al_test.go

@@ -237,7 +237,12 @@ func TestDisplayMode(t *testing.T) {
     defer UninstallSystem()
     modes := DisplayModes()
     for _, m := range modes {
-        t.Logf("Display mode: %\ns", m.String());
+        t.Logf("Display mode: %s\n", m.String());
+    }
+    
+    monitors := GetAllMonitorInfo() 
+    for _, m := range monitors {
+        t.Logf("Monitor : %s\n", m.String());
     }
 }
 

+ 15 - 0
al/display.go

@@ -9,6 +9,7 @@ import "C"
 
 import "runtime"
 import "unsafe"
+import "fmt"
 
 // Usful regexp for KATE:  ALLEGRO_([A-Z0-9_]+)(.*) -> \1 = C.ALLEGRO_\1
 
@@ -352,6 +353,20 @@ func GetMonitorInfo(index int) *MonitorInfo {
     return nil
 }
 
+func (mi * MonitorInfo) String() string {
+    return fmt.Sprintf("%d %d %d %d", mi.X1(), mi.Y1(), mi.X2(), mi.Y2())
+}
+
+// Gets all available monitors and their info
+func GetAllMonitorInfo() []*MonitorInfo {
+    count := NumVideoAdapters();
+    info := make([]*MonitorInfo, count)
+    for i := 0 ; i < count; i ++ {
+        info[i] = GetMonitorInfo(i)
+    }
+    return info
+}
+
 // Returns the number of the display adapter where new dsplays will be created
 func NewDisplayAdapter() int {
     return int(C.al_get_new_display_adapter())

+ 18 - 0
al/keyboard.go

@@ -223,3 +223,21 @@ func wrapKeyboardRaw(kb * C.ALLEGRO_KEYBOARD) * Keyboard {
     return res
 }
 
+
+type KeyboardState C.ALLEGRO_KEYBOARD_STATE
+
+func (ks * KeyboardState) toC() * C.ALLEGRO_KEYBOARD_STATE {
+    return (*C.ALLEGRO_KEYBOARD_STATE)(ks)
+}
+
+
+func GetKeyboardState() * KeyboardState {
+    ks := &KeyboardState{}
+    C.al_get_keyboard_state(ks.toC());
+    return ks
+}
+
+func (ks * KeyboardState) KeyDown(keycode int) bool {
+    return bool(C.al_key_down(ks.toC(), C.int(keycode)))
+}
+