|
@@ -6,125 +6,122 @@ package al
|
|
|
#cgo linux LDFLAGS: -lc_nonshared
|
|
|
#include <stdlib.h>
|
|
|
#include <allegro5/allegro.h>
|
|
|
+#include <allegro5/events.h>
|
|
|
#include "helpers.h"
|
|
|
*/
|
|
|
import "C"
|
|
|
|
|
|
-import "unsafe"
|
|
|
+
|
|
|
import "runtime"
|
|
|
|
|
|
const PI = 3.14159265358979323846
|
|
|
|
|
|
-
|
|
|
|
|
|
-func AL_ID(a,b,c,d int) int {
|
|
|
- return (((a)<<24) | ((b)<<16) | ((c)<<8) | (d))
|
|
|
+func AL_ID(a, b, c, d int) int {
|
|
|
+ return (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
|
|
|
}
|
|
|
|
|
|
-
|
|
|
const VERSION = 5
|
|
|
const SUB_VERSION = 0
|
|
|
const WIP_VERSION = 7
|
|
|
const RELEASE_NUMBER = 1
|
|
|
const VERSION_STR = "5.0.7"
|
|
|
-const DATE_STR = "2012"
|
|
|
-const DATE = 20120624
|
|
|
-const VERSION_INT =
|
|
|
- ((VERSION << 24) | (SUB_VERSION << 16) |
|
|
|
- (WIP_VERSION << 8) | RELEASE_NUMBER)
|
|
|
-
|
|
|
-
|
|
|
+const DATE_STR = "2012"
|
|
|
+const DATE = 20120624
|
|
|
+const VERSION_INT = ((VERSION << 24) | (SUB_VERSION << 16) |
|
|
|
+ (WIP_VERSION << 8) | RELEASE_NUMBER)
|
|
|
|
|
|
|
|
|
func IsSystemInstalled() bool {
|
|
|
- return bool(C.al_is_system_installed())
|
|
|
+ return bool(C.al_is_system_installed())
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
func GetAllegroVersion() uint32 {
|
|
|
- return uint32(C.al_get_allegro_version())
|
|
|
+ return uint32(C.al_get_allegro_version())
|
|
|
}
|
|
|
|
|
|
|
|
|
func Initialize() bool {
|
|
|
- return bool(C.algo_initialize())
|
|
|
+ return bool(C.algo_initialize())
|
|
|
}
|
|
|
|
|
|
|
|
|
func Cleanup() {
|
|
|
- C.algo_atexit_cleanup()
|
|
|
+ C.algo_atexit_cleanup()
|
|
|
}
|
|
|
|
|
|
|
|
|
func InstallSystem() bool {
|
|
|
- return bool(C.al_install_system(VERSION_INT, nil))
|
|
|
+ return bool(C.al_install_system(VERSION_INT, nil))
|
|
|
}
|
|
|
|
|
|
|
|
|
func UninstallSystem() {
|
|
|
- C.al_uninstall_system()
|
|
|
+ C.al_uninstall_system()
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
-type Path struct {
|
|
|
- handle * C.ALLEGRO_PATH
|
|
|
+type Path struct {
|
|
|
+ handle *C.ALLEGRO_PATH
|
|
|
}
|
|
|
|
|
|
|
|
|
-func wrapPathRaw(handle * C.ALLEGRO_PATH) (* Path) {
|
|
|
- if handle == nil { return nil }
|
|
|
- return &Path{handle}
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func wrapPathCleanly(handle * C.ALLEGRO_PATH,
|
|
|
- clean func(path * Path) ) (* Path) {
|
|
|
- result := wrapPathRaw(handle);
|
|
|
- if (result == nil) { return result }
|
|
|
- runtime.SetFinalizer(result, clean)
|
|
|
- return result
|
|
|
+func wrapPathRaw(handle *C.ALLEGRO_PATH) *Path {
|
|
|
+ if handle == nil {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return &Path{handle}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func wrapPath(handle * C.ALLEGRO_PATH) (* Path) {
|
|
|
- cleanup := func(path * Path) { path.Destroy() }
|
|
|
- return wrapPathCleanly(handle,cleanup);
|
|
|
+
|
|
|
+
|
|
|
+func wrapPath(handle *C.ALLEGRO_PATH) *Path {
|
|
|
+ result := wrapPathRaw(handle)
|
|
|
+ if result != nil {
|
|
|
+ runtime.SetFinalizer(result, func(me *Path) { me.Destroy() })
|
|
|
+ }
|
|
|
+ return result
|
|
|
}
|
|
|
|
|
|
|
|
|
func CreatePath(str string) *Path {
|
|
|
- cstr := C.CString(str)
|
|
|
- defer C.free(unsafe.Pointer(cstr))
|
|
|
- return wrapPath(C.al_create_path(cstr))
|
|
|
+ cstr := cstr(str)
|
|
|
+ defer cstrFree(cstr)
|
|
|
+ return wrapPath(C.al_create_path(cstr))
|
|
|
}
|
|
|
|
|
|
|
|
|
func CreatePathForDirectory(str string) *Path {
|
|
|
- cstr := C.CString(str)
|
|
|
- defer C.free(unsafe.Pointer(cstr))
|
|
|
- return wrapPath(C.al_create_path_for_directory(cstr))
|
|
|
+ cstr := cstr(str)
|
|
|
+ defer cstrFree(cstr)
|
|
|
+ return wrapPath(C.al_create_path_for_directory(cstr))
|
|
|
}
|
|
|
|
|
|
|
|
|
-func (self * Path) ClonePath() *Path {
|
|
|
- return wrapPath(C.al_clone_path(self.handle))
|
|
|
+func (self *Path) ClonePath() *Path {
|
|
|
+ return wrapPath(C.al_clone_path(self.handle))
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-func (self * Path) Destroy() {
|
|
|
- if self.handle != nil { C.al_destroy_path(self.handle) }
|
|
|
- self.handle = nil;
|
|
|
+func (self *Path) Destroy() {
|
|
|
+ if self.handle != nil {
|
|
|
+ C.al_destroy_path(self.handle)
|
|
|
+ }
|
|
|
+ self.handle = nil
|
|
|
}
|
|
|
|
|
|
-func (self * Path) GetPathNumComponents() (int) {
|
|
|
- return int(C.al_get_path_num_components(self.handle))
|
|
|
+
|
|
|
+func (self *Path) GetPathNumComponents() int {
|
|
|
+ return int(C.al_get_path_num_components(self.handle))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Path) String() string {
|
|
|
+ return gostr(C.al_path_cstr(self.handle, C.char(NATIVE_PATH_SEP)))
|
|
|
}
|
|
|
|
|
|
|
|
@@ -156,115 +153,604 @@ AL_FUNC(const char*, al_get_path_basename, (const ALLEGRO_PATH *path));
|
|
|
|
|
|
AL_FUNC(bool, al_make_path_canonical, (ALLEGRO_PATH *path));
|
|
|
|
|
|
-
|
|
|
+
|
|
|
*/
|
|
|
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
- RESOURCES_PATH = iota
|
|
|
- TEMP_PATH
|
|
|
- USER_DATA_PATH
|
|
|
- USER_HOME_PATH
|
|
|
- USER_SETTINGS_PATH
|
|
|
- USER_DOCUMENTS_PATH
|
|
|
- EXENAME_PATH
|
|
|
- LAST_PATH
|
|
|
+ RESOURCES_PATH = iota
|
|
|
+ TEMP_PATH
|
|
|
+ USER_DATA_PATH
|
|
|
+ USER_HOME_PATH
|
|
|
+ USER_SETTINGS_PATH
|
|
|
+ USER_DOCUMENTS_PATH
|
|
|
+ EXENAME_PATH
|
|
|
+ LAST_PATH
|
|
|
)
|
|
|
|
|
|
+
|
|
|
+func GetStandardPath(id int) *Path {
|
|
|
+ return wrapPath(C.al_get_standard_path(C.int(id)))
|
|
|
+}
|
|
|
|
|
|
+
|
|
|
+func SetExeName(name string) {
|
|
|
+ C.al_set_exe_name(cstr(name))
|
|
|
+}
|
|
|
|
|
|
+
|
|
|
+func SetOrgName(name string) {
|
|
|
+ C.al_set_org_name(cstr(name))
|
|
|
+}
|
|
|
|
|
|
-
|
|
|
-func GetStandardPath(int id) string {
|
|
|
-
|
|
|
-
|
|
|
-AL_FUNC(PATH *, al_get_standard_path, (int id));
|
|
|
-AL_FUNC(void, al_set_exe_name, (char const *path));
|
|
|
-
|
|
|
-AL_FUNC(void, al_set_org_name, (const char *org_name));
|
|
|
-AL_FUNC(void, al_set_app_name, (const char *app_name));
|
|
|
-AL_FUNC(const char *, al_get_org_name, (void));
|
|
|
-AL_FUNC(const char *, al_get_app_name, (void));
|
|
|
-
|
|
|
-AL_FUNC(bool, al_inhibit_screensaver, (bool inhibit));
|
|
|
+
|
|
|
+func SetAppName(name string) {
|
|
|
+ C.al_set_app_name(cstr(name))
|
|
|
+}
|
|
|
|
|
|
-*/
|
|
|
+
|
|
|
+func GetOrgName() string {
|
|
|
+ return gostr(C.al_get_org_name())
|
|
|
+}
|
|
|
|
|
|
+
|
|
|
+func GetAppName() string {
|
|
|
+ return gostr(C.al_get_app_name())
|
|
|
+}
|
|
|
|
|
|
+
|
|
|
+func InhibitScreensaver(inhibit bool) bool {
|
|
|
+ return bool(C.al_inhibit_screensaver(C.bool(inhibit)))
|
|
|
+}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
-not needed in Go, so I will just wrap the basic conversion functions */
|
|
|
+not needed in Go, so I will just wrap the basic conversion functions. */
|
|
|
|
|
|
type USTR struct {
|
|
|
- handle * C.ALLEGRO_USTR
|
|
|
+ handle *C.ALLEGRO_USTR
|
|
|
}
|
|
|
|
|
|
|
|
|
-func (self * USTR) Free() {
|
|
|
- if self.handle != nil { C.al_ustr_free(self.handle) }
|
|
|
- self.handle = nil
|
|
|
+func (self *USTR) Free() {
|
|
|
+ if self.handle != nil {
|
|
|
+ C.al_ustr_free(self.handle)
|
|
|
+ }
|
|
|
+ self.handle = nil
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *USTR) Destroy() {
|
|
|
+ self.Free()
|
|
|
}
|
|
|
|
|
|
|
|
|
-func (self * USTR) String() string {
|
|
|
- if (self.handle == nil) { return "<destroyed>" }
|
|
|
- return C.GoStringN(C.al_cstr(self.handle), C.int(C.al_ustr_size(self.handle)))
|
|
|
-}
|
|
|
+func (self *USTR) String() string {
|
|
|
+ if self.handle == nil {
|
|
|
+ return "<destroyed>"
|
|
|
+ }
|
|
|
+ return C.GoStringN(C.al_cstr(self.handle), C.int(C.al_ustr_size(self.handle)))
|
|
|
+}
|
|
|
|
|
|
|
|
|
-func wrapUSTRRaw(handle * C.ALLEGRO_USTR) (* USTR) {
|
|
|
- if handle == nil { return nil }
|
|
|
- return &USTR{handle}
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-func wrapUSTRCleanly(handle * C.ALLEGRO_USTR,
|
|
|
- clean func(ustr * USTR) ) (* USTR) {
|
|
|
- result := wrapUSTRRaw(handle);
|
|
|
- if (result == nil) { return result }
|
|
|
- runtime.SetFinalizer(result, clean)
|
|
|
- return result
|
|
|
+func wrapUSTRRaw(handle *C.ALLEGRO_USTR) *USTR {
|
|
|
+ if handle == nil {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return &USTR{handle}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-func wrapUSTR(handle * C.ALLEGRO_USTR) (* USTR) {
|
|
|
- cleanup := func(ustr * USTR) { ustr.Free() }
|
|
|
- return wrapUSTRCleanly(handle, cleanup);
|
|
|
+
|
|
|
+
|
|
|
+func wrapUSTR(handle *C.ALLEGRO_USTR) *USTR {
|
|
|
+ result := wrapUSTRRaw(handle)
|
|
|
+ if result != nil {
|
|
|
+ runtime.SetFinalizer(result, func(me *USTR) { me.Destroy() })
|
|
|
+ }
|
|
|
+ return result
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
-func USTRV(str string) (* USTR) {
|
|
|
- cstr := C.CString(str)
|
|
|
- defer C.free(unsafe.Pointer(cstr))
|
|
|
- return wrapUSTR(C.al_ustr_new(cstr))
|
|
|
+func USTRV(str string) *USTR {
|
|
|
+ cstr := cstr(str)
|
|
|
+ defer cstrFree(cstr)
|
|
|
+ return wrapUSTR(C.al_ustr_new(cstr))
|
|
|
}
|
|
|
|
|
|
|
|
|
-func USTRP(str * string) (* USTR) {
|
|
|
- return USTRV(*str)
|
|
|
+func USTRP(str *string) *USTR {
|
|
|
+ return USTRV(*str)
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-func GetTime() float64 {
|
|
|
- return float64(C.al_get_time())
|
|
|
+func GetTime() float64 {
|
|
|
+ return float64(C.al_get_time())
|
|
|
}
|
|
|
|
|
|
|
|
|
-func Rest(seconds float64) {
|
|
|
- C.al_rest(C.double(seconds))
|
|
|
+func Rest(seconds float64) {
|
|
|
+ C.al_rest(C.double(seconds))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+const (
|
|
|
+ EVENT_JOYSTICK_AXIS = C.ALLEGRO_EVENT_JOYSTICK_AXIS
|
|
|
+ EVENT_JOYSTICK_BUTTON_DOWN = C.ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN
|
|
|
+ EVENT_JOYSTICK_BUTTON_UP = C.ALLEGRO_EVENT_JOYSTICK_BUTTON_UP
|
|
|
+ EVENT_JOYSTICK_CONFIGURATION = C.ALLEGRO_EVENT_JOYSTICK_CONFIGURATION
|
|
|
+
|
|
|
+ EVENT_KEY_DOWN = C.ALLEGRO_EVENT_KEY_DOWN
|
|
|
+ EVENT_KEY_CHAR = C.ALLEGRO_EVENT_KEY_CHAR
|
|
|
+ EVENT_KEY_UP = C.ALLEGRO_EVENT_KEY_UP
|
|
|
+
|
|
|
+ EVENT_MOUSE_AXES = C.ALLEGRO_EVENT_MOUSE_AXES
|
|
|
+ EVENT_MOUSE_BUTTON_DOWN = C.ALLEGRO_EVENT_MOUSE_BUTTON_DOWN
|
|
|
+ EVENT_MOUSE_BUTTON_UP = C.ALLEGRO_EVENT_MOUSE_BUTTON_UP
|
|
|
+ EVENT_MOUSE_ENTER_DISPLAY = C.ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY
|
|
|
+ EVENT_MOUSE_LEAVE_DISPLAY = C.ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY
|
|
|
+ EVENT_MOUSE_WARPED = C.ALLEGRO_EVENT_MOUSE_WARPED
|
|
|
+
|
|
|
+ EVENT_TIMER = C.ALLEGRO_EVENT_TIMER
|
|
|
+
|
|
|
+ EVENT_DISPLAY_EXPOSE = C.ALLEGRO_EVENT_DISPLAY_EXPOSE
|
|
|
+ EVENT_DISPLAY_RESIZE = C.ALLEGRO_EVENT_DISPLAY_RESIZE
|
|
|
+ EVENT_DISPLAY_CLOSE = C.ALLEGRO_EVENT_DISPLAY_CLOSE
|
|
|
+ EVENT_DISPLAY_LOST = C.ALLEGRO_EVENT_DISPLAY_LOST
|
|
|
+ EVENT_DISPLAY_FOUND = C.ALLEGRO_EVENT_DISPLAY_FOUND
|
|
|
+ EVENT_DISPLAY_SWITCH_IN = C.ALLEGRO_EVENT_DISPLAY_SWITCH_IN
|
|
|
+ EVENT_DISPLAY_SWITCH_OUT = C.ALLEGRO_EVENT_DISPLAY_SWITCH_OUT
|
|
|
+ EVENT_DISPLAY_ORIENTATION = C.ALLEGRO_EVENT_DISPLAY_ORIENTATION
|
|
|
+)
|
|
|
+
|
|
|
+func EVENT_TYPE_IS_USER(t int) bool {
|
|
|
+ return ((t) >= 512)
|
|
|
+}
|
|
|
+
|
|
|
+func GET_EVENT_TYPE(a, b, c, d int) int {
|
|
|
+ return AL_ID(a, b, c, d)
|
|
|
+}
|
|
|
+
|
|
|
+func getAnyEvenTimestamp(any *C.ALLEGRO_ANY_EVENT) float64 {
|
|
|
+ return float64(any.timestamp)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+type EventSource C.ALLEGRO_EVENT_SOURCE
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventSource) toC() *C.ALLEGRO_EVENT_SOURCE {
|
|
|
+ return (*C.ALLEGRO_EVENT_SOURCE)(self)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+type Event C.ALLEGRO_EVENT
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) toC() *C.ALLEGRO_EVENT {
|
|
|
+ return (*C.ALLEGRO_EVENT)(self)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) Type() int {
|
|
|
+ return int(C.algo_event_type(self.toC()))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) Timestamp() float64 {
|
|
|
+ return float64(C.algo_event_any(self.toC()).timestamp)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) EventSource() *EventSource {
|
|
|
+ return (*EventSource)(C.algo_event_any(self.toC()).source)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) IsDisplay() bool {
|
|
|
+ t := self.Type()
|
|
|
+ return (t >= EVENT_DISPLAY_EXPOSE) && (t <= EVENT_DISPLAY_ORIENTATION)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) IsMouse() bool {
|
|
|
+ t := self.Type()
|
|
|
+ return (t >= EVENT_MOUSE_AXES) && (t <= EVENT_MOUSE_WARPED)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) IsJoystick() bool {
|
|
|
+ t := self.Type()
|
|
|
+ return (t >= EVENT_JOYSTICK_AXIS) && (t <= EVENT_JOYSTICK_CONFIGURATION)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) IsKeyboard() bool {
|
|
|
+ t := self.Type()
|
|
|
+ return (t >= EVENT_KEY_DOWN) && (t <= EVENT_KEY_UP)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) IsTimer() bool {
|
|
|
+ t := self.Type()
|
|
|
+ return (t == EVENT_TIMER)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) IsUser() bool {
|
|
|
+ t := self.Type()
|
|
|
+ return EVENT_TYPE_IS_USER(t)
|
|
|
+}
|
|
|
+
|
|
|
+type Display C.ALLEGRO_DISPLAY
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) DisplayDisplay() *Display {
|
|
|
+ if !(self.IsDisplay()) {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return (*Display)(C.algo_event_display(self.toC()).source)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) DisplayX() int {
|
|
|
+ return int(C.algo_event_display(self.toC()).x)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) DisplayY() int {
|
|
|
+ return int(C.algo_event_display(self.toC()).y)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) DisplayWidth() int {
|
|
|
+ return int(C.algo_event_display(self.toC()).width)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) DisplayHeight() int {
|
|
|
+ return int(C.algo_event_display(self.toC()).height)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) DisplayOrientation() int {
|
|
|
+ return int(C.algo_event_display(self.toC()).orientation)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) JoystickStick() int {
|
|
|
+ return int(C.algo_event_joystick(self.toC()).stick)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) JoystickAxis() int {
|
|
|
+ return int(C.algo_event_joystick(self.toC()).axis)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) JoystickButton() int {
|
|
|
+ return int(C.algo_event_joystick(self.toC()).button)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) JoystickPos() float32 {
|
|
|
+ return float32(C.algo_event_joystick(self.toC()).pos)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) KeyboardDisplay() *Display {
|
|
|
+ if !(self.IsKeyboard()) {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return (*Display)(C.algo_event_keyboard(self.toC()).display)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) KeyboardKeycode() int {
|
|
|
+ return int(C.algo_event_keyboard(self.toC()).keycode)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) KeyboardUnichar() rune {
|
|
|
+ return rune(C.algo_event_keyboard(self.toC()).unichar)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) KeyboardModifiers() int {
|
|
|
+ return int(C.algo_event_keyboard(self.toC()).modifiers)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) KeyboardRepeat() bool {
|
|
|
+ return bool(C.algo_event_keyboard(self.toC()).repeat)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) MouseX() int {
|
|
|
+ return int(C.algo_event_mouse(self.toC()).x)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) MouseY() int {
|
|
|
+ return int(C.algo_event_mouse(self.toC()).y)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) MouseZ() int {
|
|
|
+ return int(C.algo_event_mouse(self.toC()).z)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) MouseW() int {
|
|
|
+ return int(C.algo_event_mouse(self.toC()).w)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) MouseDX() int {
|
|
|
+ return int(C.algo_event_mouse(self.toC()).dx)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) MouseDY() int {
|
|
|
+ return int(C.algo_event_mouse(self.toC()).dy)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) MouseDZ() int {
|
|
|
+ return int(C.algo_event_mouse(self.toC()).dz)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) MouseDW() int {
|
|
|
+ return int(C.algo_event_mouse(self.toC()).dw)
|
|
|
+}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) MouseButton() int {
|
|
|
+ return int(C.algo_event_mouse(self.toC()).button)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) MousePressure() float32 {
|
|
|
+ return float32(C.algo_event_mouse(self.toC()).pressure)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) MouseDisplay() *Display {
|
|
|
+ if !(self.IsMouse()) {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return (*Display)(C.algo_event_mouse(self.toC()).display)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) TimerError() float64 {
|
|
|
+ return float64(C.algo_event_timer(self.toC()).error)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Event) TimerCount() int64 {
|
|
|
+ return int64(C.algo_event_timer(self.toC()).count)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+type EventQueue struct {
|
|
|
+ handle *C.ALLEGRO_EVENT_QUEUE
|
|
|
+}
|
|
|
|
|
|
+
|
|
|
+func (self *EventQueue) Destroy() {
|
|
|
+ if self.handle != nil {
|
|
|
+ C.al_destroy_event_queue(self.handle)
|
|
|
+ }
|
|
|
+ self.handle = nil
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func wrapEventQueueRaw(handle *C.ALLEGRO_EVENT_QUEUE) *EventQueue {
|
|
|
+ if handle == nil {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return &EventQueue{handle}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func wrapEventQueue(handle *C.ALLEGRO_EVENT_QUEUE) *EventQueue {
|
|
|
+ result := wrapEventQueueRaw(handle)
|
|
|
+ if result != nil {
|
|
|
+ runtime.SetFinalizer(result, func(me *EventQueue) { me.Destroy() })
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func CreateEventQueue() *EventQueue {
|
|
|
+ return wrapEventQueue(C.al_create_event_queue())
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) RegisterEventSource(src *EventSource) {
|
|
|
+ C.al_register_event_source(self.handle, src.toC())
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) UnregisterEventSource(src *EventSource) {
|
|
|
+ C.al_unregister_event_source(self.handle, src.toC())
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) IsEmpty() bool {
|
|
|
+ return bool(C.al_is_event_queue_empty(self.handle))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) GetNextEvent() (event *Event, ok bool) {
|
|
|
+ event = &Event{}
|
|
|
+ ok = bool(C.al_get_next_event(self.handle, event.toC()))
|
|
|
+ return event, ok
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) PeekNextEvent() (event *Event, ok bool) {
|
|
|
+ event = &Event{}
|
|
|
+ ok = bool(C.al_peek_next_event(self.handle, event.toC()))
|
|
|
+ return event, ok
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) DropNextEvent() bool {
|
|
|
+ return bool(C.al_drop_next_event(self.handle))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) Flush() {
|
|
|
+ C.al_flush_event_queue(self.handle)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) WaitForEvent() (event *Event) {
|
|
|
+ event = &Event{}
|
|
|
+ C.al_wait_for_event(self.handle, event.toC())
|
|
|
+ return event
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *EventQueue) WaitForEventTimed(secs float32) (event *Event, ok bool) {
|
|
|
+ event = &Event{}
|
|
|
+ ok = bool(C.al_wait_for_event_timed(self.handle, event.toC(), C.float(secs)))
|
|
|
+ return event, ok
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+TODO:
|
|
|
+AL_FUNC(bool, al_wait_for_event_until, (ALLEGRO_EVENT_QUEUE *queue,
|
|
|
+ ALLEGRO_EVENT *ret_event,
|
|
|
+ ALLEGRO_TIMEOUT *timeout));
|
|
|
+*/
|
|
|
+
|
|
|
+
|
|
|
+type Timer struct {
|
|
|
+ handle *C.ALLEGRO_TIMER
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Timer) Destroy() {
|
|
|
+ if self.handle != nil {
|
|
|
+ C.al_destroy_timer(self.handle)
|
|
|
+ }
|
|
|
+ self.handle = nil
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func wrapTimerRaw(handle *C.ALLEGRO_TIMER) *Timer {
|
|
|
+ if handle == nil {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ return &Timer{handle}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func wrapTimer(handle *C.ALLEGRO_TIMER) *Timer {
|
|
|
+ result := wrapTimerRaw(handle)
|
|
|
+ if result != nil {
|
|
|
+ runtime.SetFinalizer(result, func(me *Timer) { me.Destroy() })
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func CreateTimer(speed_secs float64) *Timer {
|
|
|
+ return wrapTimer(C.al_create_timer(C.double(speed_secs)))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Timer) Start() {
|
|
|
+ C.al_start_timer(self.handle)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Timer) Stop() {
|
|
|
+ C.al_stop_timer(self.handle)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Timer) IsStarted() bool {
|
|
|
+ return bool(C.al_get_timer_started(self.handle))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Timer) SetSpeed(speed_secs float64) {
|
|
|
+ C.al_set_timer_speed(self.handle, C.double(speed_secs))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Timer) GetSpeed() float64 {
|
|
|
+ return float64(C.al_get_timer_speed(self.handle))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Timer) GetCount() int {
|
|
|
+ return int(C.al_get_timer_count(self.handle))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Timer) SetCount(count int) {
|
|
|
+ C.al_set_timer_count(self.handle, C.int64_t(count))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+func (self *Timer) AddCount(count int) {
|
|
|
+ C.al_add_timer_count(self.handle, C.int64_t(count))
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+func (self *Timer) GetEventSource() *EventSource {
|
|
|
+ return (*EventSource)(C.al_get_timer_event_source(self.handle))
|
|
|
+}
|