/
display.go
188 lines (143 loc) · 5.29 KB
/
display.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package allegro
// #include <allegro5/allegro.h>
import "C"
import "unsafe"
/********************/
/* Display Creation */
/********************/
func CreateDisplay(w, h int32) *Display {
return (*Display)(unsafe.Pointer(C.al_create_display(C.int(w), C.int(h))))
}
func (d *Display) Destroy() {
C.al_destroy_display((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)))
}
func GetNewDisplayFlags() int32 {
return int32(C.al_get_new_display_flags())
}
func SetNewDisplayFlags(flags int32) {
C.al_set_new_display_flags(C.int(flags))
}
func GetNewDisplayOption(option int32) (int32, int32) {
var importance C.int
v := int32(C.al_get_new_display_option(C.int(option), &importance))
return v, int32(importance)
}
func SetNewDisplayOption(option, value, importance int32) {
C.al_set_new_display_option(C.int(option), C.int(value), C.int(importance))
}
func ResetNewDisplayOptions() {
C.al_reset_new_display_options()
}
func GetNewWindowPosition() (int32, int32) {
var x, y C.int
C.al_get_new_window_position(&x, &y)
return int32(x), int32(y)
}
func SetNewWindowPosition(x, y int32) {
C.al_set_new_window_position(C.int(x), C.int(y))
}
func GetNewDisplayRefreshRate() int32 {
return int32(C.al_get_new_display_refresh_rate())
}
func SetNewDisplayRefreshRate(refreshRate int32) {
C.al_set_new_display_refresh_rate(C.int(refreshRate))
}
/**********************/
/* Display Operations */
/**********************/
func (d *Display) GetEventSource() *EventSource {
return (*EventSource)(unsafe.Pointer(C.al_get_display_event_source((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)))))
}
func (d *Display) GetBackbuffer() *Bitmap {
return (*Bitmap)(unsafe.Pointer(C.al_get_backbuffer((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)))))
}
func FlipDisplay() {
C.al_flip_display()
}
func UpdateDisplayRegion(x, y, width, height int32) {
C.al_update_display_region(C.int(x), C.int(y), C.int(width), C.int(height))
}
func WaitForVsync() bool {
return bool(C.al_wait_for_vsync())
}
/*****************************/
/* Display Size and Position */
/*****************************/
func (d *Display) GetWidth() int32 {
return int32(C.al_get_display_width((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d))))
}
func (d *Display) GetHeight() int32 {
return int32(C.al_get_display_height((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d))))
}
func (d *Display) Resize(width, height int32) bool {
return bool(C.al_resize_display((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)), C.int(width), C.int(height)))
}
func (d *Display) AcknowledgeResize() bool {
return bool(C.al_acknowledge_resize((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d))))
}
func (d *Display) GetWindowPosition() (int32, int32) {
var x, y C.int
C.al_get_window_position((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)), &x, &y)
return int32(x), int32(y)
}
func (d *Display) SetWindowPosition(x, y int32) {
C.al_set_window_position((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)), C.int(x), C.int(y))
}
func (d *Display) GetWindowConstraints() (bool, int32, int32, int32, int32) {
var min_w, min_h, max_w, max_h C.int
r := C.al_get_window_constraints((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)), &min_w, &min_h, &max_w, &max_h)
return bool(r), int32(min_w), int32(min_h), int32(max_w), int32(max_h)
}
func (d *Display) SetWindowConstraints(min_w, min_h, max_w, max_h int32) bool {
return bool(C.al_set_window_constraints((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)), C.int(min_w), C.int(min_h), C.int(max_w), C.int(max_h)))
}
/********************/
/* Display Settings */
/********************/
func (d *Display) GetFlags() int32 {
return int32(C.al_get_display_flags((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d))))
}
func (d *Display) SetFlag(flag int, onoff bool) bool {
return bool(C.al_set_display_flag((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)), C.int(flag), C.bool(onoff)))
}
func (d *Display) GetOption(option int32) int32 {
return int32(C.al_get_display_option((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)), C.int(option)))
}
func (d *Display) SetOption(option, value int32) {
C.al_set_display_option((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)), C.int(option), C.int(value))
}
func (d *Display) GetFormat() int32 {
return int32(C.al_get_display_format((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d))))
}
func (d *Display) GetOrientation() int32 {
return int32(C.al_get_display_orientation((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d))))
}
func (d *Display) GetRefreshRate() int32 {
return int32(C.al_get_display_refresh_rate((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d))))
}
func (d *Display) SetWindowTitle(title string) {
t := C.CString(title)
defer C.free(unsafe.Pointer(t))
C.al_set_window_title((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)), t)
}
func (d *Display) SetIcon(icon *Bitmap) {
C.al_set_display_icon((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)), (*C.ALLEGRO_BITMAP)(unsafe.Pointer(icon)))
}
//func (d *Display) SetIcons(numIcons int32, icons [](*Bitmap)) {
// C.al_set_display_icons(C.int(numIcons), (**C.ALLEGRO_BITMAP)(unsafe.Pointer(&icons[0])))
//}
/*****************/
/* Drawing Halts */
/*****************/
func (d *Display) AcknowledgeDrawingHalt() {
C.al_acknowledge_drawing_halt((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)))
}
func (d *Display) AcknowledgeDrawingResume() {
C.al_acknowledge_drawing_resume((*C.ALLEGRO_DISPLAY)(unsafe.Pointer(d)))
}
/***************/
/* Screensaver */
/***************/
func InhibitScreensaver(inhibit bool) bool {
return bool(C.al_inhibit_screensaver(C.bool(inhibit)))
}