123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858 |
- package al
- 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))
- }
- const (
- VERSION = C.ALLEGRO_VERSION
- SUB_VERSION = C.ALLEGRO_SUB_VERSION
- WIP_VERSION = C.ALLEGRO_WIP_VERSION
- UNSTABLE_BIT = 0
- RELEASE_NUMBER = C.ALLEGRO_RELEASE_NUMBER
- VERSION_STR = C.ALLEGRO_VERSION_STR
- DATE_STR = C.ALLEGRO_DATE_STR
- VERSION_INT = ((VERSION << 24) | (SUB_VERSION << 16) |
- (WIP_VERSION << 8) | RELEASE_NUMBER | UNSTABLE_BIT)
- )
- func b2cb(res bool) C.bool {
- if res {
- return C.bool(true)
- }
- return C.bool(false)
- }
- func alMalloc(size uint) unsafe.Pointer {
- return C.al_malloc_with_context(C.size_t(size), 0, nil, nil)
- }
- func alCalloc(size, n uint) unsafe.Pointer {
- return C.al_calloc_with_context(C.size_t(size), C.size_t(n), 0, nil, nil)
- }
- func alFree(ptr unsafe.Pointer) {
- C.al_free_with_context(ptr, 0, nil, nil)
- }
- func cb2b(res C.bool) bool {
- if res {
- return true
- }
- return false
- }
- func IsSystemInstalled() bool {
- return bool(C.al_is_system_installed())
- }
- func GetAllegroVersion() uint32 {
- return uint32(C.al_get_allegro_version())
- }
- func Initialize() bool {
- return bool(C.al_install_system(VERSION_INT, nil))
-
- }
- func Cleanup() {
- C.al_uninstall_system()
- }
- func InstallSystem() bool {
- return bool(C.al_install_system(VERSION_INT, nil))
- }
- func UninstallSystem() {
- C.al_uninstall_system()
- }
- type Path struct {
- handle *C.ALLEGRO_PATH
- }
- func wrapPathRaw(handle *C.ALLEGRO_PATH) *Path {
- if handle == nil {
- return nil
- }
- return &Path{handle}
- }
- 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 := cstr(str)
- defer cstrFree(cstr)
- return wrapPath(C.al_create_path(cstr))
- }
- func CreatePathForDirectory(str string) *Path {
- 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) 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) String() string {
- return gostr(C.al_path_cstr(self.handle, C.char(NATIVE_PATH_SEP)))
- }
- const (
- RESOURCES_PATH = C.ALLEGRO_RESOURCES_PATH
- TEMP_PATH = C.ALLEGRO_TEMP_PATH
- USER_DATA_PATH = C.ALLEGRO_USER_DATA_PATH
- USER_HOME_PATH = C.ALLEGRO_USER_HOME_PATH
- USER_SETTINGS_PATH = C.ALLEGRO_USER_SETTINGS_PATH
- USER_DOCUMENTS_PATH = C.ALLEGRO_USER_DOCUMENTS_PATH
- EXENAME_PATH = C.ALLEGRO_EXENAME_PATH
- LAST_PATH = C.ALLEGRO_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 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)))
- }
- type USTR struct {
- handle *C.ALLEGRO_USTR
- }
- 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 wrapUSTRRaw(handle *C.ALLEGRO_USTR) *USTR {
- if handle == nil {
- return nil
- }
- return &USTR{handle}
- }
- 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 := cstr(str)
- defer cstrFree(cstr)
- return wrapUSTR(C.al_ustr_new(cstr))
- }
- func USTRP(str *string) *USTR {
- return USTRV(*str)
- }
- func GetTime() float64 {
- return float64(C.al_get_time())
- }
- 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 wrapEventSourceRaw(ptr *C.ALLEGRO_EVENT_SOURCE) *EventSource {
- return (*EventSource)(ptr)
- }
- 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) toPointer() unsafe.Pointer {
- return unsafe.Pointer(self.toC())
- }
- func (self *Event) ANY_EVENT() *C.ALLEGRO_ANY_EVENT {
- return (*C.ALLEGRO_ANY_EVENT)(self.toPointer())
- }
- func (self *Event) DISPLAY_EVENT() *C.ALLEGRO_DISPLAY_EVENT {
- return (*C.ALLEGRO_DISPLAY_EVENT)(self.toPointer())
- }
- func (self *Event) JOYSTICK_EVENT() *C.ALLEGRO_JOYSTICK_EVENT {
- return (*C.ALLEGRO_JOYSTICK_EVENT)(self.toPointer())
- }
- func (self *Event) KEYBOARD_EVENT() *C.ALLEGRO_KEYBOARD_EVENT {
- return (*C.ALLEGRO_KEYBOARD_EVENT)(self.toPointer())
- }
- func (self *Event) TOUCH_EVENT() *C.ALLEGRO_TOUCH_EVENT {
- return (*C.ALLEGRO_TOUCH_EVENT)(self.toPointer())
- }
- func (self *Event) MOUSE_EVENT() *C.ALLEGRO_MOUSE_EVENT {
- return (*C.ALLEGRO_MOUSE_EVENT)(self.toPointer())
- }
- func (self *Event) TIMER_EVENT() *C.ALLEGRO_TIMER_EVENT {
- return (*C.ALLEGRO_TIMER_EVENT)(self.toPointer())
- }
- func (self *Event) USER_EVENT() *C.ALLEGRO_USER_EVENT {
- return (*C.ALLEGRO_USER_EVENT)(self.toPointer())
- }
- func (self *Event) Type() int {
- return int(self.ANY_EVENT()._type)
- }
- func (self *Event) Timestamp() float64 {
- return float64(self.ANY_EVENT().timestamp)
- }
- func (self *Event) EventSource() *EventSource {
- return (*EventSource)(self.ANY_EVENT().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)
- }
- func (self *Event) EVENT_SOURCE() *C.ALLEGRO_EVENT_SOURCE {
- return self.ANY_EVENT().source
- }
- func (self *Event) EVENT_SOURCE_PTR() unsafe.Pointer {
- return unsafe.Pointer(self.ANY_EVENT())
- }
- func (self *Event) DisplayDisplay() *Display {
- if !(self.IsDisplay()) {
- return nil
- }
- return wrapDisplayRaw((*C.ALLEGRO_DISPLAY)(self.EVENT_SOURCE_PTR()))
- }
- func (self *Event) DisplayX() int {
- return int((self.DISPLAY_EVENT()).x)
- }
- func (self *Event) DisplayY() int {
- return int(self.DISPLAY_EVENT().y)
- }
- func (self *Event) DisplayWidth() int {
- return int(self.DISPLAY_EVENT().width)
- }
- func (self *Event) DisplayHeight() int {
- return int(self.DISPLAY_EVENT().height)
- }
- func (self *Event) DisplayOrientation() int {
- return int(self.DISPLAY_EVENT().orientation)
- }
- func (self *Event) JoystickStick() int {
- return int(self.JOYSTICK_EVENT().stick)
- }
- func (self *Event) JoystickAxis() int {
- return int(self.JOYSTICK_EVENT().axis)
- }
- func (self *Event) JoystickButton() int {
- return int(self.JOYSTICK_EVENT().button)
- }
- func (self *Event) JoystickPos() float32 {
- return float32(self.JOYSTICK_EVENT().pos)
- }
- func (self *Event) KeyboardDisplay() *Display {
- if !(self.IsKeyboard()) {
- return nil
- }
- return wrapDisplayRaw(self.KEYBOARD_EVENT().display)
- }
- func (self *Event) KeyboardKeycode() int {
- return int(self.KEYBOARD_EVENT().keycode)
- }
- func (self *Event) KeyboardUnichar() rune {
- return rune(self.KEYBOARD_EVENT().unichar)
- }
- func (self *Event) KeyboardModifiers() int {
- return int(self.KEYBOARD_EVENT().modifiers)
- }
- func (self *Event) KeyboardRepeat() bool {
- return bool(self.KEYBOARD_EVENT().repeat)
- }
- func (self *Event) MouseX() int {
- return int(self.MOUSE_EVENT().x)
- }
- func (self *Event) MouseY() int {
- return int(self.MOUSE_EVENT().y)
- }
- func (self *Event) MouseZ() int {
- return int(self.MOUSE_EVENT().z)
- }
- func (self *Event) MouseW() int {
- return int(self.MOUSE_EVENT().w)
- }
- func (self *Event) MouseDX() int {
- return int(self.MOUSE_EVENT().dx)
- }
- func (self *Event) MouseDY() int {
- return int(self.MOUSE_EVENT().dy)
- }
- func (self *Event) MouseDZ() int {
- return int(self.MOUSE_EVENT().dz)
- }
- func (self *Event) MouseDW() int {
- return int(self.MOUSE_EVENT().dw)
- }
- func (self *Event) MouseButton() int {
- return int(self.MOUSE_EVENT().button)
- }
- func (self *Event) MousePressure() float32 {
- return float32(self.MOUSE_EVENT().pressure)
- }
- func (self *Event) MouseDisplay() *Display {
- if !(self.IsMouse()) {
- return nil
- }
- return wrapDisplayRaw(self.MOUSE_EVENT().display)
- }
- func (self *Event) TimerError() float64 {
- return float64(self.TIMER_EVENT().error)
- }
- func (self *Event) TimerCount() int64 {
- return int64(self.TIMER_EVENT().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
- }
- 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))
- }
- func DoNothing() {
- }
- func Errno() int {
- return int(C.al_get_errno())
- }
|