|
@@ -0,0 +1,460 @@
|
|
|
|
+package al
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+#include <stdlib.h>
|
|
|
|
+#include <allegro5/allegro.h>
|
|
|
|
+#include "helpers.h"
|
|
|
|
+*/
|
|
|
|
+import "C"
|
|
|
|
+
|
|
|
|
+import "runtime"
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const (
|
|
|
|
+ WINDOWED = C.ALLEGRO_WINDOWED
|
|
|
|
+ FULLSCREEN = C.ALLEGRO_FULLSCREEN
|
|
|
|
+ OPENGL = C.ALLEGRO_OPENGL
|
|
|
|
+ DIRECT3D_INTERNAL = C.ALLEGRO_DIRECT3D_INTERNAL
|
|
|
|
+ RESIZABLE = C.ALLEGRO_RESIZABLE
|
|
|
|
+ FRAMELESS = C.ALLEGRO_FRAMELESS
|
|
|
|
+ NOFRAME = C.ALLEGRO_NOFRAME
|
|
|
|
+ GENERATE_EXPOSE_EVENTS = C.ALLEGRO_GENERATE_EXPOSE_EVENTS
|
|
|
|
+ OPENGL_3_0 = C.ALLEGRO_OPENGL_3_0
|
|
|
|
+ OPENGL_FORWARD_COMPATIBLE = C.ALLEGRO_OPENGL_FORWARD_COMPATIBLE
|
|
|
|
+ FULLSCREEN_WINDOW = C.ALLEGRO_FULLSCREEN_WINDOW
|
|
|
|
+ MINIMIZED = C.ALLEGRO_MINIMIZED
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const (
|
|
|
|
+ RED_SIZE = C.ALLEGRO_RED_SIZE
|
|
|
|
+ GREEN_SIZE = C.ALLEGRO_GREEN_SIZE
|
|
|
|
+ BLUE_SIZE = C.ALLEGRO_BLUE_SIZE
|
|
|
|
+ ALPHA_SIZE = C.ALLEGRO_ALPHA_SIZE
|
|
|
|
+ RED_SHIFT = C.ALLEGRO_RED_SHIFT
|
|
|
|
+ GREEN_SHIFT = C.ALLEGRO_GREEN_SHIFT
|
|
|
|
+ BLUE_SHIFT = C.ALLEGRO_BLUE_SHIFT
|
|
|
|
+ ALPHA_SHIFT = C.ALLEGRO_ALPHA_SHIFT
|
|
|
|
+ ACC_RED_SIZE = C.ALLEGRO_ACC_RED_SIZE
|
|
|
|
+ ACC_GREEN_SIZE = C.ALLEGRO_ACC_GREEN_SIZE
|
|
|
|
+ ACC_BLUE_SIZE = C.ALLEGRO_ACC_BLUE_SIZE
|
|
|
|
+ ACC_ALPHA_SIZE = C.ALLEGRO_ACC_ALPHA_SIZE
|
|
|
|
+ STEREO = C.ALLEGRO_STEREO
|
|
|
|
+ AUX_BUFFERS = C.ALLEGRO_AUX_BUFFERS
|
|
|
|
+ COLOR_SIZE = C.ALLEGRO_COLOR_SIZE
|
|
|
|
+ DEPTH_SIZE = C.ALLEGRO_DEPTH_SIZE
|
|
|
|
+ STENCIL_SIZE = C.ALLEGRO_STENCIL_SIZE
|
|
|
|
+ SAMPLE_BUFFERS = C.ALLEGRO_SAMPLE_BUFFERS
|
|
|
|
+ SAMPLES = C.ALLEGRO_SAMPLES
|
|
|
|
+ RENDER_METHOD = C.ALLEGRO_RENDER_METHOD
|
|
|
|
+ FLOAT_COLOR = C.ALLEGRO_FLOAT_COLOR
|
|
|
|
+ FLOAT_DEPTH = C.ALLEGRO_FLOAT_DEPTH
|
|
|
|
+ SINGLE_BUFFER = C.ALLEGRO_SINGLE_BUFFER
|
|
|
|
+ SWAP_METHOD = C.ALLEGRO_SWAP_METHOD
|
|
|
|
+ COMPATIBLE_DISPLAY = C.ALLEGRO_COMPATIBLE_DISPLAY
|
|
|
|
+ UPDATE_DISPLAY_REGION = C.ALLEGRO_UPDATE_DISPLAY_REGION
|
|
|
|
+ VSYNC = C.ALLEGRO_VSYNC
|
|
|
|
+ MAX_BITMAP_SIZE = C.ALLEGRO_MAX_BITMAP_SIZE
|
|
|
|
+ SUPPORT_NPOT_BITMAP = C.ALLEGRO_SUPPORT_NPOT_BITMAP
|
|
|
|
+ CAN_DRAW_INTO_BITMAP = C.ALLEGRO_CAN_DRAW_INTO_BITMAP
|
|
|
|
+ SUPPORT_SEPARATE_ALPHA = C.ALLEGRO_SUPPORT_SEPARATE_ALPHA
|
|
|
|
+ DISPLAY_OPTIONS_COUNT = C.ALLEGRO_DISPLAY_OPTIONS_COUNT
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const (
|
|
|
|
+ DONTCARE = C.ALLEGRO_DONTCARE
|
|
|
|
+ REQUIRE = C.ALLEGRO_REQUIRE
|
|
|
|
+ SUGGEST = C.ALLEGRO_SUGGEST
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const (
|
|
|
|
+ DISPLAY_ORIENTATION_0_DEGREES = C.ALLEGRO_DISPLAY_ORIENTATION_0_DEGREES
|
|
|
|
+ DISPLAY_ORIENTATION_90_DEGREES = C.ALLEGRO_DISPLAY_ORIENTATION_90_DEGREES
|
|
|
|
+ DISPLAY_ORIENTATION_180_DEGREES = C.ALLEGRO_DISPLAY_ORIENTATION_180_DEGREES
|
|
|
|
+ DISPLAY_ORIENTATION_270_DEGREES = C.ALLEGRO_DISPLAY_ORIENTATION_270_DEGREES
|
|
|
|
+ DISPLAY_ORIENTATION_FACE_UP = C.ALLEGRO_DISPLAY_ORIENTATION_FACE_UP
|
|
|
|
+ DISPLAY_ORIENTATION_FACE_DOWN = C.ALLEGRO_DISPLAY_ORIENTATION_FACE_DOWN
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+type Display struct {
|
|
|
|
+ handle *C.ALLEGRO_DISPLAY
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) Destroy() {
|
|
|
|
+ if self.handle != nil {
|
|
|
|
+ C.al_destroy_display(self.handle)
|
|
|
|
+ }
|
|
|
|
+ self.handle = nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func wrapDisplayRaw(handle *C.ALLEGRO_DISPLAY) *Display {
|
|
|
|
+ if handle == nil {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ return &Display{handle}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func wrapDisplay(handle *C.ALLEGRO_DISPLAY) *Display {
|
|
|
|
+ self := wrapDisplayRaw(handle)
|
|
|
|
+ if self != nil {
|
|
|
|
+ runtime.SetFinalizer(self, func(me *Display) { me.Destroy() })
|
|
|
|
+ }
|
|
|
|
+ return self
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+type DisplayMode C.ALLEGRO_DISPLAY_MODE
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *DisplayMode) toC() *C.ALLEGRO_DISPLAY_MODE {
|
|
|
|
+ return (*C.ALLEGRO_DISPLAY_MODE)(self)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *DisplayMode) Width() int {
|
|
|
|
+ return int(self.width)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *DisplayMode) Height() int {
|
|
|
|
+ return int(self.height)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *DisplayMode) Format() int {
|
|
|
|
+ return int(self.format)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *DisplayMode) RefreshRate() int {
|
|
|
|
+ return int(self.refresh_rate)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+type MonitorInfo C.ALLEGRO_MONITOR_INFO
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *MonitorInfo) X1() int {
|
|
|
|
+ return int(self.x1)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *MonitorInfo) Y1() int {
|
|
|
|
+ return int(self.y1)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *MonitorInfo) X2() int {
|
|
|
|
+ return int(self.x2)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *MonitorInfo) Y2() int {
|
|
|
|
+ return int(self.y2)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const (
|
|
|
|
+ DEFAULT_DISPLAY_ADAPTER = C.ALLEGRO_DEFAULT_DISPLAY_ADAPTER
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func SetNewDisplayFlags(flags int) {
|
|
|
|
+ C.al_set_new_display_flags(C.int(flags))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func CreateDisplay(width, height int) *Display {
|
|
|
|
+ return wrapDisplay(C.al_create_display(C.int(width), C.int(height)))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) Resize(width, height int) bool {
|
|
|
|
+ return bool(C.al_resize_display(self.handle, C.int(width), C.int(height)))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func FlipDisplay() {
|
|
|
|
+ C.al_flip_display()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) Flip() {
|
|
|
|
+ C.al_flip_display()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+type Color C.ALLEGRO_COLOR
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func wrapColor(color C.ALLEGRO_COLOR) Color {
|
|
|
|
+ return Color(color)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self Color) toC() C.ALLEGRO_COLOR {
|
|
|
|
+ return C.ALLEGRO_COLOR(self)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func CreateColor(r, g, b, a float32) Color {
|
|
|
|
+ return Color{C.float(r), C.float(g), C.float(b), C.float(a)}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self Color) R() float32 {
|
|
|
|
+ return float32(self.r)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self Color) G() float32 {
|
|
|
|
+ return float32(self.g)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self Color) B() float32 {
|
|
|
|
+ return float32(self.b)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self Color) A() float32 {
|
|
|
|
+ return float32(self.a)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func ClearToColor(color Color) {
|
|
|
|
+ C.al_clear_to_color(color.toC())
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func DrawPixel(x, y float32, color Color) {
|
|
|
|
+ C.al_draw_pixel(C.float(x), C.float(y), C.ALLEGRO_COLOR(color))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func SetNewDisplayRefreshRate(refresh_rate int) {
|
|
|
|
+ C.al_set_new_display_refresh_rate(C.int(refresh_rate))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func NewDisplayRefreshRate() int {
|
|
|
|
+ return int(C.al_get_new_display_refresh_rate())
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func NewDisplayFlags() int {
|
|
|
|
+ return int(C.al_get_new_display_flags())
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) Width() int {
|
|
|
|
+ return int(C.al_get_display_width(self.handle))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) Height() int {
|
|
|
|
+ return int(C.al_get_display_height(self.handle))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) RefreshRate() int {
|
|
|
|
+ return int(C.al_get_display_refresh_rate(self.handle))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) DisplayFlags() int {
|
|
|
|
+ return int(C.al_get_display_flags(self.handle))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) SetDisplayFlag(flag int, onoff bool) bool {
|
|
|
|
+ return cb2b(C.al_set_display_flag(self.handle, C.int(flag), b2cb(onoff)))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func CurrentDisplay() *Display {
|
|
|
|
+ return wrapDisplayRaw(C.al_get_current_display())
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func setTargetCBitmap(bmp *C.ALLEGRO_BITMAP) {
|
|
|
|
+ C.al_set_target_bitmap(bmp)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func SetTargetBitmap(bmp Bitmap) {
|
|
|
|
+ setTargetCBitmap(bmp.handle)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func setTargetCBackbuffer(display *C.ALLEGRO_DISPLAY) {
|
|
|
|
+ C.al_set_target_backbuffer(display)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func SetTargetBackbuffer(display *Display) {
|
|
|
|
+ setTargetCBackbuffer(display.handle)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) Backbuffer() *Bitmap {
|
|
|
|
+ return wrapBitmapRaw(C.al_get_backbuffer(self.handle))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func TargetBitmap() *Bitmap {
|
|
|
|
+ return wrapBitmapRaw(C.al_get_target_bitmap())
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) AcknowledgeResize() bool {
|
|
|
|
+ return cb2b(C.al_acknowledge_resize(self.handle))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func UpdateDisplayRegion(x, y, width, height int) {
|
|
|
|
+ C.al_update_display_region(C.int(x), C.int(y), C.int(width), C.int(height))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (bitmap *Bitmap) IsCompatibleBitmap() bool {
|
|
|
|
+ return cb2b(C.al_is_compatible_bitmap(bitmap.handle))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func NumDisplayModes() int {
|
|
|
|
+ return int(C.al_get_num_display_modes())
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *DisplayMode) Get(index int) *DisplayMode {
|
|
|
|
+ return (*DisplayMode)(C.al_get_display_mode(C.int(index), self.toC()))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func GetDisplayMode(index int) *DisplayMode {
|
|
|
|
+ var mode DisplayMode
|
|
|
|
+ if (&mode).Get(index) != nil {
|
|
|
|
+ return &mode
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func WaitForVsync() {
|
|
|
|
+ C.al_wait_for_vsync()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) GetEventSource() *EventSource {
|
|
|
|
+ return (*EventSource)(C.al_get_display_event_source(self.handle))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) SetDisplayIcon(bitmap *Bitmap) {
|
|
|
|
+ C.al_set_display_icon(self.handle, bitmap.handle)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func NumVideoAdapters() int {
|
|
|
|
+ return int(C.al_get_num_video_adapters())
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *MonitorInfo) toC() *C.ALLEGRO_MONITOR_INFO {
|
|
|
|
+ return (*C.ALLEGRO_MONITOR_INFO)(self)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *MonitorInfo) Get(index int) bool {
|
|
|
|
+ return cb2b(C.al_get_monitor_info(C.int(index), self.toC()))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func GetMonitorInfo(index int) *MonitorInfo {
|
|
|
|
+ var info MonitorInfo
|
|
|
|
+ if (&info).Get(index) {
|
|
|
|
+ return &info
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func NewDisplayAdapter() int {
|
|
|
|
+ return int(C.al_get_new_display_adapter())
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func SetNewDisplayAdapter(adapter int) {
|
|
|
|
+ C.al_set_new_display_adapter(C.int(adapter))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func NewWindowPosition() (x, y int) {
|
|
|
|
+ var cx, cy C.int
|
|
|
|
+ C.al_get_new_window_position(&cx, &cy)
|
|
|
|
+ return int(cx), int(cy)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func SetNewWindowPosition(x, y int) {
|
|
|
|
+ C.al_set_new_window_position(C.int(x), C.int(y))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) WindowPosition() (x, y int) {
|
|
|
|
+ var cx, cy C.int
|
|
|
|
+ C.al_get_window_position(self.handle, &cx, &cy)
|
|
|
|
+ return int(cx), int(cy)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) SetWindowPosition(x, y int) {
|
|
|
|
+ C.al_set_window_position(self.handle, C.int(x), C.int(y))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) SetTitle(str string) {
|
|
|
|
+ cstr := cstr(str)
|
|
|
|
+ defer cstrFree(cstr)
|
|
|
|
+ C.al_set_window_title(self.handle, cstr)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func SetNewDisplayOption(option, value, importance int) {
|
|
|
|
+ C.al_set_new_display_option(C.int(option), C.int(value), C.int(importance))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func ResetNewDisplayOptions() {
|
|
|
|
+ C.al_reset_new_display_options()
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func (self *Display) DisplayOption(option int) int {
|
|
|
|
+ return int(C.al_get_display_option(self.handle, C.int(option)))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func HoldBitmapDrawing(hold bool) {
|
|
|
|
+ C.al_hold_bitmap_drawing(b2cb(hold))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+func IsBitmapDrawingHeld() bool {
|
|
|
|
+ return cb2b(C.al_is_bitmap_drawing_held())
|
|
|
|
+}
|