forked from duarteroso/glfw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.v
162 lines (133 loc) · 4.08 KB
/
monitor.v
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
module vglfw
// Forward declaration
@[typedef]
struct C.GLFWmonitor {
}
fn C.glfwGetMonitorPos(monitor &C.GLFWmonitor, x_pos &int, y_pos &int)
fn C.glfwGetMonitorWorkarea(monitor &C.GLFWmonitor, x_pos &int, y_pos &int, width &int, height &int)
fn C.glfwGetMonitorPhysicalSize(monitor &C.GLFWmonitor, widthMM &int, heightMM &int)
fn C.glfwGetMonitorContentScale(monitor &C.GLFWmonitor, x_scale &f32, y_scale &f32)
fn C.glfwGetMonitorName(monitor &C.GLFWmonitor) &char
fn C.glfwSetMonitorUserPointer(monitor &C.GLFWmonitor, pointer voidptr)
fn C.glfwGetMonitorUserPointer(monitor &C.GLFWmonitor) voidptr
fn C.glfwGetVideoModes(monitor &C.GLFWmonitor, count &int) &C.GLFWvidmode
fn C.glfwGetVideoMode(monitor &C.GLFWmonitor) &C.GLFWvidmode
fn C.glfwSetGamma(monitor &C.GLFWmonitor, gamma f32)
fn C.glfwGetGammaRamp(monitor &C.GLFWmonitor) &C.GLFWgammaramp
fn C.glfwSetGammaRamp(monitor &C.GLFWmonitor, ramp &C.GLFWgammaramp)
// Monitor wraps the functionality of GLFWmonitor
pub struct Monitor {
mut:
data &C.GLFWmonitor = &C.GLFWmonitor(unsafe { 0 })
}
// MonitorDesc describes the basic properties of a Monitor
pub struct MonitorDesc {
pub mut:
pos Position
size Size
refresh_rate int
}
// create_monitor creates a Monitor instance from raw data
pub fn create_monitor(data &C.GLFWmonitor) &Monitor {
unsafe {
return &Monitor{
data: data
}
}
}
// set_data links data to a monitor
pub fn (mut m Monitor) set_data(data &C.GLFWmonitor) {
unsafe {
m.data = data
}
}
// get_pos returns the position of the monitor
pub fn (m &Monitor) get_pos() !Position {
pos := Position{}
C.glfwGetMonitorPos(m.data, &int(pos.x), &int(pos.y))
check_error()!
return pos
}
// get_workarea returns the workarea of the monitor
pub fn (m &Monitor) get_workarea() !(Position, Size) {
pos := Position{}
size := Size{}
C.glfwGetMonitorWorkarea(m.data, &int(pos.x), &int(pos.y), &size.width, &size.height)
check_error()!
return pos, size
}
// get_physical_size returns the physical size of the monitor
pub fn (m &Monitor) get_physical_size() !Size {
size := Size{}
C.glfwGetMonitorPhysicalSize(m.data, &size.width, &size.height)
check_error()!
return size
}
// get_content_scale returns the content scale of the monitor
pub fn (m &Monitor) get_content_scale() !Scale {
scale := Scale{}
C.glfwGetMonitorContentScale(m.data, &scale.x, &scale.y)
check_error()!
return scale
}
// get_name returns the name of the monitor
pub fn (m &Monitor) get_name() !string {
name := C.glfwGetMonitorName(m.data)
check_error()!
return unsafe { name.vstring() }
}
// set_user_pointer links user data to the monitor
pub fn (m &Monitor) set_user_pointer(pointer voidptr) ! {
C.glfwSetMonitorUserPointer(m.data, pointer)
check_error()!
}
// get_user_pointer returns the linked user data of the monitor
pub fn (m &Monitor) get_user_pointer() !voidptr {
ptr := C.glfwGetMonitorUserPointer(m.data)
check_error()!
return ptr
}
// get_video_modes returns an array of video modes supported by the monitor
pub fn (m &Monitor) get_video_modes() ![]VideoMode {
count := 0
c_modes := C.glfwGetVideoModes(m.data, &count)
check_error()!
//
mut v_modes := []VideoMode{len: count}
for idx := 0; idx < count; idx++ {
unsafe {
v_modes[idx] = create_vidmode(&c_modes[idx])
}
}
//
return v_modes
}
// get_current_video_mode returns the current video mode of the monitor
pub fn (m &Monitor) get_current_video_mode() !VideoMode {
vidmode := C.glfwGetVideoMode(m.data)
check_error()!
return create_vidmode(vidmode)
}
// set_gamma sets the monitor gamma value
pub fn (m &Monitor) set_gamma(gamma f32) ! {
C.glfwSetGamma(m.data, gamma)
check_error()!
}
// get_gamma_ramp returns the GamaRamp instance of the monitor
// Returns nil if GammaRamp is missing
pub fn (m &Monitor) get_gamma_ramp() !&GammaRamp {
raw_data := C.glfwGetGammaRamp(m.data)
check_error()!
//
if isnil(raw_data) {
return &GammaRamp(unsafe { 0 })
}
//
gr := create_gammaramp(raw_data)
return gr
}
// set_gamma_ramp sets the gamma ramp of the monitor
pub fn (m &Monitor) set_gamma_ramp(gr GammaRamp) ! {
C.glfwSetGammaRamp(m.data, gr.get_raw())
check_error()!
}